importJar('org.jsoup:jsoup:jar:1.12.1');

importClass("org.jsoup.Jsoup");
var CHROME_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 " +
    "(KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36";

/**
 * 请求.
 * @param url
 * @param retryTimes
 * @returns {*}
 */
function httpGet(url, retryTimes) {
    var throwException = null;
    if (null == retryTimes) {
        retryTimes = 3;
    }
    for (var i = 0; i < retryTimes; i++) {
        try {
            var connect = Jsoup.connect(url);
            connect.userAgent(CHROME_USER_AGENT);
            connect.timeout(60000);
            connect.ignoreContentType(true);
            return connect.execute();
        } catch (e) {
            try {
                util.sleep(1000);
            } catch (ignored) {
            }
            throwException = e;
        }
    }
    throw throwException;
}


function httpGetBody(url, retryTimes) {
    return httpGet(url, retryTimes).body();
}

function httpGetBodyAsBytes(url, retryTimes) {
    return httpGet(url, retryTimes).body();
}


